<?php
    /**
    * Base Controller Extensible.
    *
    * Helpful methods to make Controller.
    *
    * PHP versions 5
    * CAKEPHP versions 2.x
    * 
    * Green CMS - Content Management System and Framework Powerfull by Cakephp
    * Copyright 2012, GREEN GLOBAL CO., LTD (toancauxanh.vn)
    * 
    * CakePHP(tm) :  Rapid Development Framework (http://www.cakephp.org)
    * Copyright 2005-2011, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
    *
    * Licensed under The MIT License
    * Redistributions of files must retain the above copyright notice.
    *
    * @author        Technology Lab No.I <tech1@toancauxanh.vn>
    * @link          
    * @package       Green.Controller
    * @since         Green v 1.0
    * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
    */
    App::uses('Controller', 'Controller');
    /**
    * Autocomple in PHP's IDE solution
    * 
    * @property SessionComponent $Session
    * @property RequestHandlerComponent $RequestHandler
    * @property SecurityComponent $Security
    * @property DashboardComponent $Dashboard
    */
    Class AppController extends Controller {    
        /**
        * Components
        *
        * @var array
        */
        public $components = array(
            'Cookie',
            'Cart',
            'Session',
            'Process',
            'Security' => array(
                'blackHoleCallback' => 'blackHole'
            ),
            'Auth' => array(
                'authorize' => array(
                    'Actions' => array()
                )
            )
        );
        /**
        * Helpers
        *
        * @var array
        */
        public $helpers = array(
            'Session',
            'Html' => array(
                'className' => 'HookHtml'
            ),
            'Form' => array(
                'className' => 'HookForm'
            ),
            'Time',
            'Layout',
            'Menu', 
            'String',
            'Image',
            'Tree',
            'Currency'
        );
        /**
        * View
        *
        * @var string
        */
        public $viewClass = 'Theme';    
        /**
        * Theme
        *
        * @var string
        */
        public $theme = 'Green';
        /**
        * Theme
        *
        * @var string
        */
        // public $layout ='home';
        /**
        * Theme
        *
        * @var string
        */
        public $themeType = null;
        /**
        * Application is startup
        *
        * @see parent::constructClasses
        * @return void
        */
        public function constructClasses() {
            $this->_preloadHooks();
            Router::startup($this);
            if ($this->request->is('mobile')) {
                $this->_parseRequest();
            }
            parent::constructClasses();
            $this->_preloadAuthorize();
            $this->_maintenanceMode();
            $this->loadAppearance();
        }
        /**
        * Called before the view is rendered
        *
        * @see parent::beforeRender
        * @return void
        */
        public function beforeRender() {
            Configure::write('App.allowedActions', $this->Auth->allowedActions());
            parent::beforeRender();
        }
        /**
        * Application is shutdown
        *
        * @see parent::constructClasses
        * @return void
        */
        public function shutdownProcess() {
            parent::shutdownProcess();
            $this->response->body($this->transform($this->response->body()));
        }
        /**
        * Disable token in index action
        *
        * @return void
        */
        public function beforeFilter() {        
            parent::beforeFilter();
            $this->Cookie->time = 86400;
            if ($this->request['action'] === 'admin_index') {
                $this->Components->disable('Security');
            }
            if (Router::getParam('admin')) {
                $this->Dashboard = $this->Components->load('System.Dashboard');
                $this->helpers[] = 'Node.NodeFieldHook';
                // @todo fly load component and hook component and helper on backend or front end 
            }
            if (isset($this->Security)) {
                $this->Security->unlockedFields = array('task');
            } 
            $user = $this->Auth->user();
            $listRole = $_listSubSite = array();
            $is_administrator = false;        
            if(!empty($user)){
                foreach($user['Role'] as $k=>$v){
                    if($v['UserRole']['role_id']==3){
                        $is_administrator = true; 
                    }
                    $listRole[] = $v['UserRole']['role_id'];
                }
            }
            Configure::write('Is_Administrator',$is_administrator);
            $this->listRole = $listRole;
            $this->isAdministrator = $is_administrator;
            if(!empty($listRole)){
                foreach($listRole as $value){
                    $this->loadModel('User.Role');
                    $sub_site = $this->Role->find('first',array(
                            'conditions'=>array('Role.id'=>$value),
                            'recursive'=>-1
                        ));
                    if(!empty($sub_site)){
                        $_listSubSite[] = $sub_site['Role']['subsite'];
                    }
                }
            }
            $_SESSION['listRole'] = $listRole;
            $_SESSION['_listSubSite'] = $_listSubSite;
            $_SESSION['isAdministrator'] = $is_administrator;        
        }
        /**
        * Convert response encoding 
        * 
        * @param string $content , the content will convert encoding.
        * @return boolean true if send content to browser , boolean false if only convert
        * @return content has convert encoding
        */
        public function loadAppearance($theme = null, $extract = false) {
            $config = Configure::read('App.themes');
            if (is_null($theme)) {
                if (empty($this->themeType)) {
                    $this->themeType = Router::getParam('admin') ? 'back' : 'front';
                }
                if (!isset($config['default'][$this->themeType])) {
                    if (empty($this->theme)) {
                        return;
                    }
                    $theme = $this->theme;
                } else {
                    $default = $config['default'][$this->themeType];
                    if ($default) {
                        $this->theme = $theme = $default;
                    } else {
                        return;
                    }
                }
            }
            if (!in_array($theme, $config['installed']) || !in_array($theme, $config['enabled'])) {
                throw new ConfigureException(__d('debug', 'System error, %s theme is not available or not active', $theme));
            }
            Configure::load('Theme.' . $theme);
            if ($extract === false) {
                return;
            }
            return Set::extract($extract, Configure::read('Themes.' . $theme));
        }

        /**
        * Redirects to given $url, after turning off $this->autoRender.
        * Script execution is halted after the redirect.
        *
        * @param mixed $url A string or array-based URL pointing to another location within the app,
        *     or an absolute URL
        * @param integer $status Optional HTTP status code (eg: 404)
        * @param boolean $exit If true, exit() will be called after the redirect
        * @return mixed void if $exit = false. Terminates script if $exit = true
        * @todo remove it if cakephp fix http://cakephp.lighthouseapp.com/projects/42648/tickets/2917-cakeresponse-problem-in-develop-mode
        */
        public function redirect($url, $status = null, $exit = true) {
            if (headers_sent()) {
                trigger_error(__d('debug', 'Cannot modify header information – headers already sent'), E_USER_ERROR);
            }
            parent::redirect($url, $status, $exit);
        }

        /**
        /**
        * Convert response encoding 
        * 
        * @param string $content , the content will convert encoding.
        * @return boolean true if send content to browser , boolean false if only convert
        * @return content has convert encoding
        */
        public function transform($content) {
            $charset = $this->response->charset();
            if (strtolower($charset) !== strtolower(Configure::read('App.encoding'))) {
                $content = mb_convert_encoding($content, $charset, 'auto');
            }
            return $content;
        }

        /**
        * Used to set a session variable that can be used to output messages in the view.
        *
        * @param string $message Message to be flashed
        * @param array $params Parameters to be sent to layout as view variables
        * @param string $key Message key, default is 'flash'
        * @param string $element Element to wrap flash message in.
        * @return void
        */
        public function setFlash($message, $params = array(), $key = 'flash', $element = 'flash') {
            $maps = array(
                'error' => __d('green', 'Error'),
                'info' => __d('green', 'Information'),
                'warning' => __d('green', 'Warning'),
                'success' => __d('green', 'Success')
            );
            if (!is_array($params)) {
                $params = array('type' => $params);
            }
            if (empty($params['type']) || !array_key_exists($params['type'], $maps)) {
                $params['type'] = 'error';
            }
            $params = array_merge(array('title' => $maps[$params['type']]), $params);
            $this->Session->setFlash($message, $element, $params, $key);
        }
        /**
        * Security callback hole.
        *
        * @param string $error
        * @return void
        */
        public function blackHole($error = null) {
            //debug($error);exit;
            switch (strtolower($error)) {
                case 'auth' : {
                    $this->setFlash(__d('green', 'Security error , data sent to the server by the browser is not valid authentication. Please try again'));
                    $this->redirect($this->request->here(false), null, true);
                }
                case 'csrf' : {
                    $this->setFlash(__d('green', 'Security error , Time pending submission of your form has expired or is your data has been sent to the server is duplicated . Please try again'));
                    $this->redirect($this->request->here(false), null, true);
                }
                default : {
                    throw new SecurityException(
                        __d('green', 'Security error , The actions that require a request that is %s.', array(Inflector::humanize($error)))
                    );
                }
            }
        }
        /**
        * Load config Hooks
        * 
        * @return void
        */
        protected function _preloadHooks() {
            foreach (CakePlugin::loaded() as $plugin) {
                $hooks = Configure::read('Modules.' . $plugin);
                foreach (array('components', 'helpers') as $type) {
                    if (!empty($hooks[$type])) {
                        $this->{$type} = array_merge($this->{$type}, (array) $hooks[$type]);
                    }
                }
            }
            //$this->_mergeVars(array('components', 'helpers'), 'ExController', false);
        }

        /**
        * Load config for Authorize
        * 
        * @return void
        */
        protected function _preloadAuthorize() {
            $configs = Configure::read('Authorize');
            if (isset($configs['activated']) && $configs['activated'] == false) {
                $this->Components->disable('Auth');
            }
            unset($configs['activated']);
            $this->Auth->loginAction = array(
                'controller' => 'user',
                'plugin' => 'user',
                'action' => 'login',
                'admin' => true,
            );
            $this->Auth->flash = array(
                'element' => 'flash',
                'key' => 'auth',
                'params' => array(
                    'type' => 'error',
                    'title' => __d('system', 'Error')
                )
            );

            if (!empty($configs) && is_array($configs)) {
                foreach ($configs as $key => $config) {
                    if (isset($this->Auth->{$key}) && is_array($this->Auth->{$key})) {
                        $config = array_merge($this->Auth->{$key}, (array) $config);
                    }
                    $this->Auth->{$key} = $config;
                }
            }
        }
        /**
        * Parse request datas
        * 
        * @return void
        */
        protected function _parseRequest() {
            $encodingLists = Router::getConfig('encodingLists');
            if ($encodingLists && is_string($encodingLists)) {
                mb_convert_variables(Configure::read('App.encoding'), $encodingLists, $this->request->data, $this->request->query);
            }
        }

        /**
        * Check maintenance mode
        * 
        * @return void
        */
        protected function _maintenanceMode() {
            $config = Configure::read('Maintenance');
            $allowed = false;
            if (!empty($config['activated']) && (empty($config['time']) || strtotime($config['time']) <= time())) {
                $allowed = Router::normalize($this->request->url) == Router::normalize($this->Auth->loginAction);
                if (!$allowed) {
                    if (!empty($config['allowedActions']) && in_array($this->request->params['action'], (array) $config['allowedActions'])) {
                        $allowed = true;
                    } elseif (($user = $this->Auth->user())) {
                        $request = new CakeRequest(null, false);
                        $request->params = array_merge($request->params, array(
                                'plugin' => 'System',
                                'controller' => 'system',
                                'action' => 'maintenance'));
                        $allowed = $this->Auth->isAuthorized($user, $request);
                    }
                }
                if ($allowed) {
                    Configure::write('App.maintenance', true);
                } else {
                    throw new MaintenanceException(__($config['message']));
                }
            }
        }
        public function support_seo($seo=array()){
            //Lấy thông tin SEO mặc định từ cấu hình
            $content = array();                        
            $conds = array();
            $fields = $this->Process->nodeFields();
            $opt = array(
                'conditions' => $conds,
                'find' => 'first'
            );    
            $content = self::get_data('Node','Node',$opt);
            $opt_default = array(
                'title_for_layout' => __d('default','USIS'),
                'description_for_layout' =>__d('default',"U.S. Investment Services"),
                'keywords_for_layout' => __d('default',"usis") 
            );
            if(!empty($seo)){
                if(!empty($seo['keywords_for_layout'])) $seo['keywords_for_layout'] =  $opt_default['keywords_for_layout'] . ',' . $seo['keywords_for_layout'];
                $opt_default = array_merge($opt_default,$seo);
            }
            $this->set('title_for_layout', $opt_default['title_for_layout']);
            $this->set('description_for_layout', $opt_default['description_for_layout']);
            $this->set('keywords_for_layout',$opt_default['keywords_for_layout']);
        }
        public function get_data($model_parent=null,$model_child=null,$options=array()){        
            $data = array();            
            if((empty($model_parent))&&(empty($model_child))){return 'Vui lòng truyền $model_parent & $model_child';}
            $options_default = array(
                'conditions' => array(),
                'find' => 'all',
                'page' => null,
                'fields' => false,
                'order' => $model_child . '.' . 'id desc',
                'locale' => true,
                'limit' => false,                
                'pagination' => false,
                'recursive' => null            
            );            
            if(!empty($options)){$options_default = array_merge($options_default,$options);}                
            $this->loadModel($model_parent . '.' . $model_child);
            $Model = ClassRegistry::init($model_parent . '.' . $model_child);                                            
            //Trường hợp không có pagination            
            if(!$options_default['pagination']){
                //Trường hợp mode_child là NodeTerm
                if(strcmp($model_child,'NodeTerm')==0) 
                {                        
                    $Model->Behaviors->attach('Translator');
                    $data = $Model->find($options_default['find'],array(
                            'conditions' => $options_default['conditions'],
                            'locale' => $options_default['locale'],
                            'contain' => array(
                                $model_parent => array(
                                    'fields' => $options_default['fields']
                                )
                            ),
                            'limit' => $options_default['limit'],
                            'order' => $options_default['order']                            
                        ));                        
                    return $data;    
                }
                $data = $Model->find($options_default['find'],array(
                        'conditions' => $options_default['conditions'],
                        'locale' => $options_default['locale'],
                        'limit' => $options_default['limit'],
                        'order' => $options_default['order'],
                        'fields' => $options_default['fields'],
                        'recursive' => $options_default['recursive']
                    ));                  
            }
            //Trường hợp có pagination                        
            if($options_default['pagination']){
                if(strcmp($model_child,'NodeTerm')==0){
                    $Model->Behaviors->attach('Translator');
                    $this->paginate = array(
                        'conditions' => $options_default['conditions'],
                        'locale' => $options_default['locale'],                        
                        'limit' => $options_default['limit'],
                        'order' => $options_default['order'],
                        'page' => $options_default['page'], 
                        'contain' => array(
                            $model_parent => array(
                                'fields' => $options_default['fields']
                            )
                        ),                                        
                        'recursive' => $options_default['recursive']
                    );                 
                    $data = $this->paginate($model_parent. '.' . $model_child); 
                    return $data;
                }                
                $this->paginate = array(
                    'conditions' => $options_default['conditions'],
                    'locale' => $options_default['locale'],
                    'limit' => $options_default['limit'],
                    'page' => $options_default['page'],                    
                    'order' => $options_default['order'],                    
                    'fields' => $options_default['fields'],                    
                    'recursive' => $options_default['recursive']
                );
                $data = $this->paginate($model_child);                                                                                                 
            }                                                                                 
            return $data;
        }
        /**
        * Debug
        * 
        * @return void
        */
        public function showDebug() {
            include CAKE . DS . 'View' . DS . 'Elements' . DS . 'sql_dump.ctp';
            exit();
        }    
        public function defineLocale() 
        {

            $_I18nCatalog = array('af' => array('language' => 'Afrikaans', 'locale' => 'afr', 'localeFallback' => 'afr', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'ar' => array('language' => 'Arabic', 'locale' => 'ara', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'),
                'ar-ae' => array('language' => 'Arabic (U.A.E.)', 'locale' => 'ar_ae', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'),
                'ar-bh' => array('language' => 'Arabic (Bahrain)', 'locale' => 'ar_bh', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'),
                'ar-dz' => array('language' => 'Arabic (Algeria)', 'locale' => 'ar_dz', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'),
                'ar-eg' => array('language' => 'Arabic (Egypt)', 'locale' => 'ar_eg', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'),
                'ar-iq' => array('language' => 'Arabic (Iraq)', 'locale' => 'ar_iq', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'),
                'ar-jo' => array('language' => 'Arabic (Jordan)', 'locale' => 'ar_jo', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'),
                'ar-kw' => array('language' => 'Arabic (Kuwait)', 'locale' => 'ar_kw', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'),
                'ar-lb' => array('language' => 'Arabic (Lebanon)', 'locale' => 'ar_lb', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'),
                'ar-ly' => array('language' => 'Arabic (Libya)', 'locale' => 'ar_ly', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'),
                'ar-ma' => array('language' => 'Arabic (Morocco)', 'locale' => 'ar_ma', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'),
                'ar-om' => array('language' => 'Arabic (Oman)', 'locale' => 'ar_om', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'),
                'ar-qa' => array('language' => 'Arabic (Qatar)', 'locale' => 'ar_qa', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'),
                'ar-sa' => array('language' => 'Arabic (Saudi Arabia)', 'locale' => 'ar_sa', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'),
                'ar-sy' => array('language' => 'Arabic (Syria)', 'locale' => 'ar_sy', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'),
                'ar-tn' => array('language' => 'Arabic (Tunisia)', 'locale' => 'ar_tn', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'),
                'ar-ye' => array('language' => 'Arabic (Yemen)', 'locale' => 'ar_ye', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'),
                'be' => array('language' => 'Byelorussian', 'locale' => 'bel', 'localeFallback' => 'bel', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'bg' => array('language' => 'Bulgarian', 'locale' => 'bul', 'localeFallback' => 'bul', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'bo' => array('language' => 'Tibetan', 'locale' => 'bod', 'localeFallback' => 'bod', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'bo-cn' => array('language' => 'Tibetan (China)', 'locale' => 'bo_cn', 'localeFallback' => 'bod', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'bo-in' => array('language' => 'Tibetan (India)', 'locale' => 'bo_in', 'localeFallback' => 'bod', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'bs' => array('language' => 'Bosnian', 'locale' => 'bos', 'localeFallback' => 'bos', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'ca' => array('language' => 'Catalan', 'locale' => 'cat', 'localeFallback' => 'cat', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'cs' => array('language' => 'Czech', 'locale' => 'cze', 'localeFallback' => 'cze', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'da' => array('language' => 'Danish', 'locale' => 'dan', 'localeFallback' => 'dan', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'de' => array('language' => 'German (Standard)', 'locale' => 'deu', 'localeFallback' => 'deu', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'de-at' => array('language' => 'German (Austria)', 'locale' => 'de_at', 'localeFallback' => 'deu', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'de-ch' => array('language' => 'German (Swiss)', 'locale' => 'de_ch', 'localeFallback' => 'deu', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'de-de' => array('language' => 'German (Germany)', 'locale' => 'de_de', 'localeFallback' => 'deu', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'de-li' => array('language' => 'German (Liechtenstein)', 'locale' => 'de_li', 'localeFallback' => 'deu', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'de-lu' => array('language' => 'German (Luxembourg)', 'locale' => 'de_lu', 'localeFallback' => 'deu', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'e' => array('language' => 'Greek', 'locale' => 'gre', 'localeFallback' => 'gre', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'el' => array('language' => 'Greek', 'locale' => 'gre', 'localeFallback' => 'gre', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'en' => array('language' => 'English', 'locale' => 'eng', 'localeFallback' => 'eng', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'en-au' => array('language' => 'English (Australian)', 'locale' => 'en_au', 'localeFallback' => 'eng', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'en-bz' => array('language' => 'English (Belize)', 'locale' => 'en_bz', 'localeFallback' => 'eng', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'en-ca' => array('language' => 'English (Canadian)', 'locale' => 'en_ca', 'localeFallback' => 'eng', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'en-gb' => array('language' => 'English (British)', 'locale' => 'en_gb', 'localeFallback' => 'eng', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'en-ie' => array('language' => 'English (Ireland)', 'locale' => 'en_ie', 'localeFallback' => 'eng', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'en-jm' => array('language' => 'English (Jamaica)', 'locale' => 'en_jm', 'localeFallback' => 'eng', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'en-nz' => array('language' => 'English (New Zealand)', 'locale' => 'en_nz', 'localeFallback' => 'eng', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'en-tt' => array('language' => 'English (Trinidad)', 'locale' => 'en_tt', 'localeFallback' => 'eng', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'en-us' => array('language' => 'English (United States)', 'locale' => 'en_us', 'localeFallback' => 'eng', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'en-za' => array('language' => 'English (South Africa)', 'locale' => 'en_za', 'localeFallback' => 'eng', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'es' => array('language' => 'Spanish (Spain - Traditional)', 'locale' => 'spa', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'es-ar' => array('language' => 'Spanish (Argentina)', 'locale' => 'es_ar', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'es-bo' => array('language' => 'Spanish (Bolivia)', 'locale' => 'es_bo', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'es-cl' => array('language' => 'Spanish (Chile)', 'locale' => 'es_cl', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'es-co' => array('language' => 'Spanish (Colombia)', 'locale' => 'es_co', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'es-cr' => array('language' => 'Spanish (Costa Rica)', 'locale' => 'es_cr', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'es-do' => array('language' => 'Spanish (Dominican Republic)', 'locale' => 'es_do', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'es-ec' => array('language' => 'Spanish (Ecuador)', 'locale' => 'es_ec', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'es-es' => array('language' => 'Spanish (Spain)', 'locale' => 'es_es', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'es-gt' => array('language' => 'Spanish (Guatemala)', 'locale' => 'es_gt', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'es-hn' => array('language' => 'Spanish (Honduras)', 'locale' => 'es_hn', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'es-mx' => array('language' => 'Spanish (Mexican)', 'locale' => 'es_mx', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'es-ni' => array('language' => 'Spanish (Nicaragua)', 'locale' => 'es_ni', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'es-pa' => array('language' => 'Spanish (Panama)', 'locale' => 'es_pa', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'es-pe' => array('language' => 'Spanish (Peru)', 'locale' => 'es_pe', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'es-pr' => array('language' => 'Spanish (Puerto Rico)', 'locale' => 'es_pr', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'es-py' => array('language' => 'Spanish (Paraguay)', 'locale' => 'es_py', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'es-sv' => array('language' => 'Spanish (El Salvador)', 'locale' => 'es_sv', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'es-uy' => array('language' => 'Spanish (Uruguay)', 'locale' => 'es_uy', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'es-ve' => array('language' => 'Spanish (Venezuela)', 'locale' => 'es_ve', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'et' => array('language' => 'Estonian', 'locale' => 'est', 'localeFallback' => 'est', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'eu' => array('language' => 'Basque', 'locale' => 'baq', 'localeFallback' => 'baq', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'fa' => array('language' => 'Farsi', 'locale' => 'per', 'localeFallback' => 'per', 'charset' => 'utf-8', 'direction' => 'rtl'),
                'fi' => array('language' => 'Finnish', 'locale' => 'fin', 'localeFallback' => 'fin', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'fo' => array('language' => 'Faeroese', 'locale' => 'fao', 'localeFallback' => 'fao', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'fr' => array('language' => 'French (Standard)', 'locale' => 'fre', 'localeFallback' => 'fre', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'fr-be' => array('language' => 'French (Belgium)', 'locale' => 'fr_be', 'localeFallback' => 'fre', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'fr-ca' => array('language' => 'French (Canadian)', 'locale' => 'fr_ca', 'localeFallback' => 'fre', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'fr-ch' => array('language' => 'French (Swiss)', 'locale' => 'fr_ch', 'localeFallback' => 'fre', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'fr-fr' => array('language' => 'French (France)', 'locale' => 'fr_fr', 'localeFallback' => 'fre', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'fr-lu' => array('language' => 'French (Luxembourg)', 'locale' => 'fr_lu', 'localeFallback' => 'fre', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'ga' => array('language' => 'Irish', 'locale' => 'gle', 'localeFallback' => 'gle', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'gd' => array('language' => 'Gaelic (Scots)', 'locale' => 'gla', 'localeFallback' => 'gla', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'gd-ie' => array('language' => 'Gaelic (Irish)', 'locale' => 'gd_ie', 'localeFallback' => 'gla', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'gl' => array('language' => 'Galician', 'locale' => 'glg', 'localeFallback' => 'glg', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'he' => array('language' => 'Hebrew', 'locale' => 'heb', 'localeFallback' => 'heb', 'charset' => 'utf-8', 'direction' => 'rtl'),
                'hi' => array('language' => 'Hindi', 'locale' => 'hin', 'localeFallback' => 'hin', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'hr' => array('language' => 'Croatian', 'locale' => 'hrv', 'localeFallback' => 'hrv', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'hu' => array('language' => 'Hungarian', 'locale' => 'hun', 'localeFallback' => 'hun', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'hy' => array('language' => 'Armenian - Armenia', 'locale' => 'hye', 'localeFallback' => 'hye', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'id' => array('language' => 'Indonesian', 'locale' => 'ind', 'localeFallback' => 'ind', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'in' => array('language' => 'Indonesian', 'locale' => 'ind', 'localeFallback' => 'ind', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'is' => array('language' => 'Icelandic', 'locale' => 'ice', 'localeFallback' => 'ice', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'it' => array('language' => 'Italian', 'locale' => 'ita', 'localeFallback' => 'ita', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'it-ch' => array('language' => 'Italian (Swiss) ', 'locale' => 'it_ch', 'localeFallback' => 'ita', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'ja' => array('language' => 'Japanese', 'locale' => 'jpn', 'localeFallback' => 'jpn', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'ko' => array('language' => 'Korean', 'locale' => 'kor', 'localeFallback' => 'kor', 'charset' => 'kr', 'direction' => 'ltr'),
                'ko-kp' => array('language' => 'Korea (North)', 'locale' => 'ko_kp', 'localeFallback' => 'kor', 'charset' => 'kr', 'direction' => 'ltr'),
                'ko-kr' => array('language' => 'Korea (South)', 'locale' => 'ko_kr', 'localeFallback' => 'kor', 'charset' => 'kr', 'direction' => 'ltr'),
                'koi8-r' => array('language' => 'Russian', 'locale' => 'koi8_r', 'localeFallback' => 'rus', 'charset' => 'koi8-r', 'direction' => 'ltr'),
                'lt' => array('language' => 'Lithuanian', 'locale' => 'lit', 'localeFallback' => 'lit', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'lv' => array('language' => 'Latvian', 'locale' => 'lav', 'localeFallback' => 'lav', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'mk' => array('language' => 'FYRO Macedonian', 'locale' => 'mk', 'localeFallback' => 'mac', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'mk-mk' => array('language' => 'Macedonian', 'locale' => 'mk_mk', 'localeFallback' => 'mac', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'ms' => array('language' => 'Malaysian', 'locale' => 'may', 'localeFallback' => 'may', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'mt' => array('language' => 'Maltese', 'locale' => 'mlt', 'localeFallback' => 'mlt', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'n' => array('language' => 'Dutch (Standard)', 'locale' => 'dut', 'localeFallback' => 'dut', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'nb' => array('language' => 'Norwegian Bokmal', 'locale' => 'nob', 'localeFallback' => 'nor', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'nl' => array('language' => 'Dutch (Standard)', 'locale' => 'dut', 'localeFallback' => 'dut', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'nl-be' => array('language' => 'Dutch (Belgium)', 'locale' => 'nl_be', 'localeFallback' => 'dut', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'nn' => array('language' => 'Norwegian Nynorsk', 'locale' => 'nno', 'localeFallback' => 'nor', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'no' => array('language' => 'Norwegian', 'locale' => 'nor', 'localeFallback' => 'nor', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'p' => array('language' => 'Polish', 'locale' => 'pol', 'localeFallback' => 'pol', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'pl' => array('language' => 'Polish', 'locale' => 'pol', 'localeFallback' => 'pol', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'pt' => array('language' => 'Portuguese (Portugal)', 'locale' => 'por', 'localeFallback' => 'por', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'pt-br' => array('language' => 'Portuguese (Brazil)', 'locale' => 'pt_br', 'localeFallback' => 'por', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'rm' => array('language' => 'Rhaeto-Romanic', 'locale' => 'roh', 'localeFallback' => 'roh', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'ro' => array('language' => 'Romanian', 'locale' => 'rum', 'localeFallback' => 'rum', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'ro-mo' => array('language' => 'Romanian (Moldavia)', 'locale' => 'ro_mo', 'localeFallback' => 'rum', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'ru' => array('language' => 'Russian', 'locale' => 'rus', 'localeFallback' => 'rus', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'ru-mo' => array('language' => 'Russian (Moldavia)', 'locale' => 'ru_mo', 'localeFallback' => 'rus', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'sb' => array('language' => 'Sorbian', 'locale' => 'wen', 'localeFallback' => 'wen', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'sk' => array('language' => 'Slovak', 'locale' => 'slo', 'localeFallback' => 'slo', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'sl' => array('language' => 'Slovenian', 'locale' => 'slv', 'localeFallback' => 'slv', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'sq' => array('language' => 'Albanian', 'locale' => 'alb', 'localeFallback' => 'alb', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'sr' => array('language' => 'Serbian', 'locale' => 'scc', 'localeFallback' => 'scc', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'sv' => array('language' => 'Swedish', 'locale' => 'swe', 'localeFallback' => 'swe', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'sv-fi' => array('language' => 'Swedish (Finland)', 'locale' => 'sv_fi', 'localeFallback' => 'swe', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'sx' => array('language' => 'Sutu', 'locale' => 'sx', 'localeFallback' => 'sx', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'sz' => array('language' => 'Sami (Lappish)', 'locale' => 'smi', 'localeFallback' => 'smi', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'th' => array('language' => 'Thai', 'locale' => 'tha', 'localeFallback' => 'tha', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'tn' => array('language' => 'Tswana', 'locale' => 'tsn', 'localeFallback' => 'tsn', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'tr' => array('language' => 'Turkish', 'locale' => 'tur', 'localeFallback' => 'tur', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'ts' => array('language' => 'Tsonga', 'locale' => 'tso', 'localeFallback' => 'tso', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'uk' => array('language' => 'Ukrainian', 'locale' => 'ukr', 'localeFallback' => 'ukr', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'ur' => array('language' => 'Urdu', 'locale' => 'urd', 'localeFallback' => 'urd', 'charset' => 'utf-8', 'direction' => 'rtl'),
                've' => array('language' => 'Venda', 'locale' => 'ven', 'localeFallback' => 'ven', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'vi' => array('language' => 'Vietnamese', 'locale' => 'vie', 'localeFallback' => 'vie', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'cy' => array('language' => 'Welsh', 'locale' => 'cym', 'localeFallback' => 'cym', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'xh' => array('language' => 'Xhosa', 'locale' => 'xho', 'localeFallback' => 'xho', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'yi' => array('language' => 'Yiddish', 'locale' => 'yid', 'localeFallback' => 'yid', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'zh' => array('language' => 'Chinese', 'locale' => 'chi', 'localeFallback' => 'chi', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'zh-cn' => array('language' => 'Chinese (PRC)', 'locale' => 'zh_cn', 'localeFallback' => 'chi', 'charset' => 'GB2312', 'direction' => 'ltr'),
                'zh-hk' => array('language' => 'Chinese (Hong Kong)', 'locale' => 'zh_hk', 'localeFallback' => 'chi', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'zh-sg' => array('language' => 'Chinese (Singapore)', 'locale' => 'zh_sg', 'localeFallback' => 'chi', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'zh-tw' => array('language' => 'Chinese (Taiwan)', 'locale' => 'zh_tw', 'localeFallback' => 'chi', 'charset' => 'utf-8', 'direction' => 'ltr'),
                'zu' => array('language' => 'Zulu', 'locale' => 'zul', 'localeFallback' => 'zul', 'charset' => 'utf-8', 'direction' => 'ltr'));
            return $_I18nCatalog;                                   
        } 
    }
?>